import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QRadioButton, QButtonGroup
from PyQt5.QtCore import pyqtSlot

def on_button_toggle(btn: QRadioButton):
    print(btn.text(), btn.isChecked())
    
def init_weiget(w:QWidget):
    w.setWindowTitle("单选框")
    # w.resize(680, 480)
    layout = QHBoxLayout()
    w.setLayout(layout)
    
    btn1 = QRadioButton("男")
    btn2 = QRadioButton("女")
    btn3 = QRadioButton("妖")
    btn3.setChecked(True)
    
    group = QButtonGroup(w)
    group.addButton(btn1)
    group.addButton(btn2)
    group.addButton(btn3)
    group.buttonToggled.connect(on_button_toggle)
    
    
    layout.addWidget(btn1)
    layout.addWidget(btn2)
    layout.addWidget(btn3)
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    w  = QWidget()
    init_weiget(w)
    w.show()
    sys.exit(app.exec_())
